/*
 * Copyright (C) 2011 Macambira Team
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.view;

import com.googlecode.services.Facade;
import com.googlecode.entity.Professor;
import com.googlecode.exception.ProfessorException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 * GUI de busca de professor
 *
 * @version 0.3 28 Out 2011
 * @author Italo Cesar | italo.fernandes@dce.ufpb.br
 */
public class TelaBuscarProfessor extends javax.swing.JFrame {

    /** Creates new form TelaBuscarProfessor */
    public TelaBuscarProfessor() {
        this.f = new Facade().getInstance();
        initComponents();
        this.labelProfessorNaoEncontrado.setVisible(false);
        this.buttonEditar.setVisible(false);
        }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jLabel6 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        siape = new javax.swing.JTextField();
        buttonBuscarSiape = new javax.swing.JButton();
        buttonVoltarSiape = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        buttonBuscarNome = new javax.swing.JButton();
        buttonVoltarNome = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        buttonEditar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        telefone2Resposta = new javax.swing.JTextField();
        telefoneResposta = new javax.swing.JTextField();
        emailResposta = new javax.swing.JTextField();
        siapeResposta = new javax.swing.JTextField();
        nomeResposta = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        buttonLimparTela = new javax.swing.JButton();
        labelProfessorNaoEncontrado = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel6.setFont(new java.awt.Font("Purisa", 1, 18));

        jPanel8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel7.setFont(new java.awt.Font("Monospaced", 1, 24));
        jLabel7.setText("SiSAP - 0.1.2");

        jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel8.setText("Cadastro de Professores");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap(531, Short.MAX_VALUE)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addContainerGap(48, Short.MAX_VALUE))
        );

        jLabel2.setText("Digite o SIAPE:");

        buttonBuscarSiape.setText("Buscar...");
        buttonBuscarSiape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBuscarSiapeActionPerformed(evt);
            }
        });

        buttonVoltarSiape.setText("Voltar");
        buttonVoltarSiape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVoltarSiapeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(siape, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(buttonVoltarSiape, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonBuscarSiape)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(siape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonBuscarSiape)
                    .addComponent(buttonVoltarSiape))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("SIAPE", jPanel1);

        jLabel3.setText("Digite o Nome do Professor:");

        buttonBuscarNome.setText("Buscar...");
        buttonBuscarNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBuscarNomeActionPerformed(evt);
            }
        });

        buttonVoltarNome.setText("Voltar");
        buttonVoltarNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVoltarNomeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nome, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(buttonVoltarNome, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonBuscarNome)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonBuscarNome)
                    .addComponent(buttonVoltarNome))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Nome", jPanel2);

        jInternalFrame1.setVisible(true);

        buttonEditar.setText("Editar...");
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel1.setText("SIAPE:");

        jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel4.setText("Nome:");

        jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel5.setText("Email:");

        jLabel9.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel9.setText("Telefone:");

        jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 15));
        jLabel10.setText("Telefone 2:");

        jButton2.setText("Deletar ");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel1))
                        .addGap(4, 4, 4)
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(siapeResposta, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                            .addComponent(nomeResposta, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                            .addComponent(emailResposta, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                            .addComponent(telefoneResposta, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                            .addComponent(telefone2Resposta, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(buttonEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(siapeResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(nomeResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(emailResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(telefoneResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(telefone2Resposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(buttonEditar))
                .addContainerGap())
        );

        buttonLimparTela.setText("Limpar Tela");
        buttonLimparTela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLimparTelaActionPerformed(evt);
            }
        });

        labelProfessorNaoEncontrado.setFont(new java.awt.Font("Ubuntu", 1, 15));
        labelProfessorNaoEncontrado.setForeground(new java.awt.Color(253, 10, 10));
        labelProfessorNaoEncontrado.setText("Atenção: O não existe nenhum professor com os dados fornecidos!!! ");

        jButton1.setText("Listar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel6))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(26, 26, 26))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(buttonLimparTela))))
                            .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jInternalFrame1)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(133, Short.MAX_VALUE)
                .addComponent(labelProfessorNaoEncontrado)
                .addGap(118, 118, 118))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(labelProfessorNaoEncontrado)
                .addGap(26, 26, 26)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonLimparTela)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(213, 213, 213)
                .addComponent(jInternalFrame1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void buttonBuscarNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBuscarNomeActionPerformed
    Professor p = null;
        try {
            try {
                p = this.f.getProfessorNome(this.nome.getText());
            } catch (SQLException ex) {
                Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.jInternalFrame1.setTitle(p.getNome().toUpperCase());
            resposta(p);    
            if (p != null){
                    this.buttonEditar.setVisible(true);
                }
        } catch (NullPointerException ex2){
            Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex2);
            this.labelProfessorNaoEncontrado.setVisible(true);
        }    
    
}//GEN-LAST:event_buttonBuscarNomeActionPerformed

private void buttonVoltarNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVoltarNomeActionPerformed
    setVisible(false);
}//GEN-LAST:event_buttonVoltarNomeActionPerformed

private void buttonBuscarSiapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBuscarSiapeActionPerformed
    Professor p2 = null;
        try {
            try {
                p2 = this.f.getProfessorID(this.siape.getText());
            } catch (SQLException ex) {
                Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
            }
            resposta(p2);
                
            if (p2 != null){
                this.buttonEditar.setVisible(true);
            }
        }catch (NullPointerException ex2){
            Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex2);
            this.labelProfessorNaoEncontrado.setVisible(true);
            try {
                this.labelProfessorNaoEncontrado.wait(0, 5);
            } catch (InterruptedException ex) {
                Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
}//GEN-LAST:event_buttonBuscarSiapeActionPerformed

private void buttonLimparTelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLimparTelaActionPerformed
    limparResposta();
}//GEN-LAST:event_buttonLimparTelaActionPerformed

private void buttonVoltarSiapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVoltarSiapeActionPerformed
    setVisible(false);
}//GEN-LAST:event_buttonVoltarSiapeActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        try {
            editarDados(this.f.getProfessorID(this.siapeResposta.getText()));
        } catch (SQLException ex) {
            Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }//GEN-LAST:event_buttonEditarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        new TelaListarProfessores();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try {
            this.deletarProfessor();
            this.limparResposta();
        } catch (ProfessorException ex) {
            Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
        }catch (NullPointerException ex2){
             Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex2);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void resposta(Professor p){
            this.jInternalFrame1.setTitle(p.getNome().toUpperCase());
            this.siapeResposta.setText(p.getId());
            this.nomeResposta.setText(p.getNome());
            this.emailResposta.setText(p.getEmail());
            this.telefoneResposta.setText(p.getTelefone());
            this.telefone2Resposta.setText(p.getTelefoneOpcional());
    }
    
    private void limparResposta(){
            this.nome.setText("");
            this.siape.setText("");
            this.labelProfessorNaoEncontrado.setVisible(false);
            this.buttonEditar.setVisible(false);
            this.jInternalFrame1.setTitle("");
            this.siapeResposta.setText("");
            this.nomeResposta.setText("");
            this.emailResposta.setText("");
            this.telefoneResposta.setText("");
            this.telefone2Resposta.setText("");
    
    }
    
    private void deletarProfessor() throws ProfessorException{
            int opc = JOptionPane.showConfirmDialog(null, "Deseja realmente deletar os dados?");
            
            if (opc == 0){
            try {
                this.f.removeProfessorID(this.siapeResposta.getText());
            } catch (SQLException ex) {
                Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
            }
            }else{
                this.setVisible(false);
            }
        
    }
    
    
    private void editarDados(Professor aux){
            int flag = JOptionPane.showConfirmDialog(null, "Deseja realmente editar?");
        
            if (flag == 0){
                Professor p = null;
            try {
                p = this.f.getObjetoProfessor(aux);
            } catch (SQLException ex) {
                Logger.getLogger(TelaBuscarProfessor.class.getName()).log(Level.SEVERE, null, ex);
            }
                p.setNome(this.nomeResposta.getText());
                p.setId(this.siapeResposta.getText());
                p.setEmail(this.emailResposta.getText());
                p.setTelefone(this.telefoneResposta.getText());
                p.setTelefoneOpcional(this.telefone2Resposta.getText());
            }else if (flag == -1){
                this.setVisible(false);
            }
        
        
    }
    
    /**
     * the main stay here! =D
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaBuscarProfessor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaBuscarProfessor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaBuscarProfessor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaBuscarProfessor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaBuscarProfessor().setVisible(true);
            }
        });
    }
    
    Facade f;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonBuscarNome;
    private javax.swing.JButton buttonBuscarSiape;
    private javax.swing.JButton buttonEditar;
    private javax.swing.JButton buttonLimparTela;
    private javax.swing.JButton buttonVoltarNome;
    private javax.swing.JButton buttonVoltarSiape;
    private javax.swing.JTextField emailResposta;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel labelProfessorNaoEncontrado;
    private javax.swing.JTextField nome;
    private javax.swing.JTextField nomeResposta;
    private javax.swing.JTextField siape;
    private javax.swing.JTextField siapeResposta;
    private javax.swing.JTextField telefone2Resposta;
    private javax.swing.JTextField telefoneResposta;
    // End of variables declaration//GEN-END:variables
}
